#ifndef DEFINE_H
#define DEFINE_H


#define     byte                  unsigned char
#define     ON                    0x01
#define     OFF                   0x00
#define     PRO_MAX_SIZE          500         //工程列表及结构体最大数量
#define     BUF_RECV_SIZE         200         //socket接收最大的字节数量
#define     BUF_SEND_SIZE         300         //socket发送最大的字节数量

//手爪控制
#define   GRIPPER_CLOSE      0x01      //手爪闭合
#define   GRIPPER_OPEN       0x00      //手爪开合

//控制模式
#define     SIM_MODE            0x00        //仿真模式
#define     REAL_ROBOT          0x01        //真实机械臂控制

//末端最大负载,5kg
#define     MAX_PAYLOAD            5

//灵巧手设置
#define   HAND_GESTUTE_CMD    0x00      //灵巧手动作手势设置
#define   HAND_SEQ_CMD        0x01      //灵巧手动作序列设置

//仿真模式限位及步长
#define SIM_JOINT_STEP      10        //关节示教步长,     100 °/s
#define SIM_TCP_STEP        0.005    //位置示教步长,      5cm/s
#define SIM_ROTATE_STEP     0.04    //姿态示教步长,     0.26rad/s
#define UPPER_LIMIT         170      //关节最大限位
#define LOWER_LIMIT         -170     //关节最小限位

//步进模式步长
#define JOINT_STEP          0.1      //步进模式关节步长分辨率
#define JOINT_STEP_MAX      100      //关节示教最大步长
#define JOINT_STEP_MIN      0.5      //关节示教最小步长

#define POSE_STEP           0.0001      //步进模式位置步长分辨率
#define POSE_STEP_MAX       0.5       //位置示教最大步长
#define POSE_STEP_MIN       0.0001      //位置示教最小步长

#define ORT_STEP            0.001      //步进模式姿态步长分辨率
#define ORT_STEP_MAX        3        //姿态示教最大步长
#define ORT_STEP_MIN        0.001      //姿态示教最小步长

#define ORT_STEP2            0.01      //步进模式姿态步长分辨率2
#define ORT_STEP_MAX2        180        //姿态示教最大步长2
#define ORT_STEP_MIN2        0.05      //姿态示教最小步长2
//**********************机械臂示教状态***********************//
#define NONE_TEACH    0x00
//关节示教
#define JOINT_1_POS   0x11
#define JOINT_2_POS   0x12
#define JOINT_3_POS   0x13
#define JOINT_4_POS   0x14
#define JOINT_5_POS   0x15
#define JOINT_6_POS   0x16
#define JOINT_7_POS   0x17

#define JOINT_1_NEG   0x01
#define JOINT_2_NEG   0x02
#define JOINT_3_NEG   0x03
#define JOINT_4_NEG   0x04
#define JOINT_5_NEG   0x05
#define JOINT_6_NEG   0x06
#define JOINT_7_NEG   0x07

//位置示教状态
#define TCP_X_POS    0x21
#define TCP_X_NEG    0x20
#define TCP_Y_POS    0x31
#define TCP_Y_NEG    0x30
#define TCP_Z_POS    0x41
#define TCP_Z_NEG    0x40

//姿态示教状态
#define TCP_RX_POS    0x51
#define TCP_RX_NEG    0x50
#define TCP_RY_POS    0x61
#define TCP_RY_NEG    0x60
#define TCP_RZ_POS    0x71
#define TCP_RZ_NEG    0x70

//回零位示教
#define GO_ZERO       0x80
#define GO_INIT       0x90
#define GO_PACKAGE    0x91

//末端参数回复默认值
#define INIT_LINE_SPEED       0.1
#define INIT_LINE_ACC         0.5
#define INIT_ANGULAR_SPEED    0.2
#define INIT_ANGULAR_ACC      1.0


//末端工具接口板电源输出
#define TOOL_VOLTAGE_0V       0
#define TOOL_VOLTAGE_5V       1
#define TOOL_VOLTAGE_12V      2
#define TOOL_VOLTAGE_24V      3

//打包姿态
float package_state[7] = {90, -114, 0, 106, 0, 112, -90};    //正式产品打包姿态

//float package_state[7] = {0, -130, 0, 130, 0, 90, 0};    //销售展示打包

//文件接受有误，行数
int project_start_end_false = 0;
//手爪状态
typedef struct
{
    byte state;  //开合状态
    int speed;        //运动速度
    int force;   //力矩设置
    int position;       //位置
}GRIPPER_STATE;
GRIPPER_STATE Gripper_State;

//灵巧手状态
typedef struct
{
    byte state;   //指令类型
    int num;      //目标数
}HAND_STATE;
HAND_STATE Hand_State;
/************************运动学解算数据******************/

//位置
typedef struct
{
    //position
    float x;
    float y;
    float z;
    //orientation
    float w;
    float x_;
    float y_;
    float z_;
}POSE;
//姿态
typedef struct
{
    float rx;
    float ry;
    float rz;
}ORT;
//欧拉角计算数据，坐标系转换使用
typedef struct
{
float px;
float py;
float pz;
float rx;
float ry;
float rz;
}Euler;

//坐标系负载和重心
typedef struct
{
float weight;
float Cx;
float Cy;
float Cz;
}Euler_load;

typedef struct
{
    POSE pose;
    ORT ort;
}KINEMATIC;

//在线编程队列点
typedef struct
{
    byte Cmd_Type;     //轨迹类型
    float data1;
    float data2;
    float data3;
    float data4;
    float data5;
    float data6;
    float data7;
    //MOVC循环圈数
    int loop;
}PROJECT_CMD;

//Socket发送队列数据结构体
typedef struct
{
    int len;                     //该次发送字节数量
    char data[BUF_SEND_SIZE];    //发送数据
}Socket_Tx_Data;


//旋转矩阵
typedef struct
{
    int irow;
    int iline;
    float data[4][4];
}Matrix;
Matrix Tool_Matrix;     //工具矩阵
Matrix Frame_Matrix;    //坐标系矩阵
//仿真状态
typedef struct
{
    POSE pose;
    ORT ort;
    float joint_cmd[7];
    float joint_pre[7];
    byte Teach_Mode;         //示教模式
    KINEMATIC target0;      //圆弧规划使用
}SIM_STATE;
SIM_STATE Sim_State;
KINEMATIC Sim_State_start;
//在线编程仿真数据
typedef struct
{
    KINEMATIC target[2];   //目标位置,MOVL-使用1，MOVC-使用1和2
    float joint[7];        //目标角度
    byte pro_type;       //规划类型，MOVJ，MOVL，MOVC
    int loop;             //movec圈数
    int re;//用来评估是否一圈要结束
    int nn;//用来记走了几个整圈
}SIM_PRO_STATE;
SIM_PRO_STATE Sim_Pro_State;
//std::ofstream _save_trajectory_file;
int _save_trajectory_number;

float Trajectory_Point[7];   //拖动示教点位
int Trajectory_Gripper;   //拖动示教点位
int Popup_number;       //弹窗提示行数
int State_Drag_Teach;       //拖动示教状态
int Drag_Teach_Name_Number;         //拖动示教轨迹名称数量
int Drag_Teach_Number_Read;         //读取拖动示教的轨迹点数
float Read_Array[7];                //读取拖动示教的点位

float Force_List4[7] = {0,0,0,0,0,0,0};            //6维力标定点位
float Force_List5[7] = {0,0,0,0,0,0,0};            //1维力标定点位
float Force_List6[7] = {0,0,0,0,0,0,0};            //1维力标定点位

float Upload_Array[7];              //上传拖动示教的点位

float Force_Fn[6] = {0,0,0,0,0,0};
byte Force_State[6];
int Force_Fn_Max = 0;
int Force_Fn_Min = 0;

int Calibrate_time = 0;

float Joint_Odom[7] = {0,0,0,0,0,0,0};  //关节里程数

float Accuracy_DH_data[5] = {0,0,0,0,0};

//关节限位信息
typedef struct
{
    float speed[7];      //最大速度
    float acc[7];        //最大加速度
    float min_limit[7];  //最小限位
    float max_limit[7];  //最大限位
}JOINT_LIMIT;
JOINT_LIMIT Joint_Limit;

//力位混合控制结构体
typedef struct
{
    int mode;
    int level;
}FORCE_POSITION;
FORCE_POSITION Force_Position;

typedef struct
{
    byte data[4];
}CHECK_FLOAT;

//示波器图像分辨率
typedef struct
{
    int X_Div;
    int Y_Div;
}WAVE_IMAGE;

WAVE_IMAGE Wave_Image;

#endif // DEFINE_H
